﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;

namespace Caffeine.Core
{
    /// <summary>
    /// Allows you to mark a field as a backing field for a ModelCommand. This type is meant
    /// to be used by the code generated from CVMF snippets.
    /// </summary>
    [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
    public sealed class ModelCommandBackingPropertyAttribute : Attribute
    {
        #region State

        private readonly String _actionMethodName;
        private readonly String _predicateMethodName;
        private readonly Type _parameterType;

        #endregion

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="actionMethodName">Name of the action to execute for this command</param>
        /// <param name="predicateMethodName">Name of the predicate used to query whether or not the command can execute</param>
        /// <param name="parameterType">Type of parameter accepted by the command</param>
        public ModelCommandBackingPropertyAttribute(String actionMethodName, String predicateMethodName, Type parameterType)
        {
            if (String.IsNullOrEmpty(actionMethodName))
            {
                throw new ArgumentNullException("actionMethodName");
            }

            if (String.IsNullOrEmpty(predicateMethodName))
            {
                throw new ArgumentNullException("predicateMethodName");
            }

            if (parameterType == null)
            {
                throw new ArgumentNullException("parameterType");
            }

            _actionMethodName = actionMethodName;
            _predicateMethodName = predicateMethodName;
            _parameterType = parameterType;
        }

        #endregion

        #region Public

        /// <summary>
        /// Gets the name of the method that will be executed for this command
        /// </summary>
        public String ActionMethodName
        {
            get
            {
                return _actionMethodName;
            }
        }

        /// <summary>
        /// Gets the name of the method that will be used to query whether or not this command can execute
        /// </summary>
        public String PredicateMethodName
        {
            get
            {
                return _predicateMethodName;
            }
        }

        /// <summary>
        /// Gets the type of parameter used by this command
        /// </summary>
        public Type ParameterType
        {
            get
            {
                return _parameterType;
            }
        }

        #endregion
    }
}
